package com.ling.ling_push;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import java.net.URL;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Activity extends AppCompatActivity {

    @BindView(R.id.button)
    Button button;
    @BindView(R.id.button1)
    Button button1;
    @BindView(R.id.button2)
    Button button2;
    @BindView(R.id.button3)
    Button button3;
    @BindView(R.id.button4)
    Button button4;
    private String URL = "rtmp://192.168.1.161/myapp/mystream";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.button, R.id.button1, R.id.button2, R.id.button3, R.id.button4})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.button:
                String URL1 = "rtmp://18955m188k.iask.in/myapp/mystream";
                // getURL(null,null,"请输入完整的流媒体服务器地址+"\r\n"+"例如：rtmp://baidu.com"");
                mystartActvity(URL1);
                break;
            case R.id.button1:
               getURL("rtmp://",":1935/bw803/idste","请输入idst服务器地址"+"\r\n"+"例如：192.168.1.1");
                break;
            case R.id.button2:
                getURL("rtmp://",":8554/video/1","请输入奥威亚录播服务器地址"+"\r\n"+"例如：192.168.1.1");
                break;
            case R.id.button3:
               getURL("rtmp://","/myapp/mystream","仅限本人搭建的流媒体服务器"+"\r\n"+"输入IP地址例如：192.168.1.1");
                break;
            case R.id.button4:
                mystartActvity(URL);
                break;
        }
    }

    private void mystartActvity(String url) {
        Log.e("Activity", "URL：" + url);
        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra("URL", url);
        startActivity(intent);
    }

    private void getURL(String host,String post,String msg){
        //弹出密码输入框
        final EditText editText = new EditText(this);
        final String mhost = host;
        final String mpost = post;
        new AlertDialog.Builder(this).setTitle(msg).setIcon(
                android.R.drawable.ic_dialog_info).setView(
                editText).setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                final String murl=  host+ editText.getText().toString()+post;
                Log.d("geturl",murl);
                mystartActvity(murl);
            }
        })
                .setNegativeButton("取消", null).show();
    }
}
